﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;

namespace ULSDeobfuscator {
    public class ObservableHashSet<T> : HashSet<T>, INotifyCollectionChanged  {

        public event NotifyCollectionChangedEventHandler CollectionChanged;

        public ObservableHashSet(IEqualityComparer<T> comparer) : base(comparer) { } 

        public new void Clear(){
            base.Clear();

            FireCompleteCollectionChanged();
        }

        public new bool Add(T item){

            bool result = base.Add(item);

            if (result){
                FireAdded(item);
            }
            return result;
        }

        private void FireAdded(T item){
            if (CollectionChanged != null){
                CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, Count - 1));
            }
        }

        protected void FireCompleteCollectionChanged(){

            if (CollectionChanged != null){
                CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }
    }
}
